home *** CD-ROM | disk | FTP | other *** search
/ Aminet 23 / Aminet 23 (1998)(GTI - Schatztruhe)[!][Feb 1998].iso / Aminet / util / cli / LibMon.lha / Src / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-10-28  |  3.3 KB  |  153 lines

  1. /* Include files */
  2. #include <exec/types.h>
  3. #include <exec/execbase.h>
  4. #include <dos/rdargs.h>
  5. #include <clib/dos_protos.h>
  6.  
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9.  
  10. #include "global.h"
  11. #include "load.h"
  12. #include "list.h"
  13. #include "flush.h"
  14. #include "output.h"
  15.  
  16.  
  17. /* ReadArgs structure and related constants */
  18. #define LA_TEMPLATE    "LIBS=LIBNAMES/M,A=ALL/S,L=LIST/S,F=FLUSH/S"
  19.  
  20. struct LibArgs {
  21.   /* These will be set by ReadArgs() ... */
  22.   STRPTR  *LIBNAMES;
  23.   ULONG   ALL;
  24.   ULONG   LIST;
  25.   ULONG   FLUSH;
  26.   
  27.   /* And this will be set by me */
  28.   ULONG   Flags;
  29. };
  30.  
  31. /* LibArgs.Flags bit numbers */
  32. #define LAFB_LIBNAMES    31
  33. #define LAFB_ALL    0
  34. #define LAFB_LIST    1
  35. #define    LAFB_FLUSH    2
  36.  
  37. /* LibArgs.Flags values */
  38. #define LAFF_NONE    0
  39. #define LAFF_LIBNAMES    (1<<LAFB_LIBNAMES)
  40. #define LAFF_ALL    (1<<LAFB_ALL)
  41. #define LAFF_LIST    (1<<LAFB_LIST)
  42. #define LAFF_FLUSH    (1<<LAFB_FLUSH)
  43.  
  44.  
  45.  
  46. extern struct ExecBase *SysBase;
  47. struct RDArgs *rdargs;
  48.  
  49.  
  50. /* Initialise global variables */
  51. void init_globals(void)
  52. {
  53.   rdargs = NULL;
  54. }
  55.  
  56.  
  57. /* Exit without hassle */
  58. /* RC - return code eg 5=warning, 10=error, 20=failure, 100=armageddon etc */
  59. void clean_exit(int RC)
  60. {
  61.   /* Free the ReadArgs structure if allocated */
  62.   if (rdargs) FreeArgs(rdargs);
  63.   
  64.   exit(RC);
  65. }
  66.  
  67. /* Disable automatic program abortion if present */
  68. void chkabort(void) {return;}
  69.  
  70.  
  71. /* Start of the Program */
  72. int main(int argc, char *argv[])
  73. {
  74.   struct LibArgs LibArgs = {NULL, FALSE, FALSE, FALSE, LAFF_NONE};
  75.   int i;
  76.   
  77.   init_globals();
  78.   OutputHeader();
  79.   
  80.   /* Check the OS version */
  81.   if (SysBase->LibNode.lib_Version < 36)
  82.   {
  83.     /* I don't know, some people... *sigh* */
  84.     fputs("Hey! What's the matter with you? 1.3 sux! Get OS2 now, then\n",stderr);
  85.     fputs("you too can run this cool program!\n",stderr);
  86.     clean_exit(20);
  87.   }
  88.   
  89.   /* Collect the arguments */
  90.   rdargs = ReadArgs(LA_TEMPLATE,(LONG *)&LibArgs,NULL);
  91.   if (!rdargs)
  92.   {
  93.     OutputUsage();
  94.     clean_exit(5);
  95.   }
  96.   
  97.   LibArgs.Flags = ((LibArgs.LIBNAMES != NULL) << LAFB_LIBNAMES) |
  98.                   ((LibArgs.ALL & 1) << LAFB_ALL) |
  99.                   ((LibArgs.LIST & 1) << LAFB_LIST) |
  100.                   ((LibArgs.FLUSH & 1) << LAFB_FLUSH);
  101.   
  102.   switch (LibArgs.Flags)
  103.   {
  104.   
  105.   /*-- No library names, ALL flag set --*/
  106.   case (LAFF_ALL):
  107.     LoadLibs();
  108.     break;
  109.   
  110.   /*-- No library names, LIST flag, or ALL and LIST flags set --*/
  111.   case (LAFF_LIST):
  112.   case (LAFF_LIST | LAFF_ALL):
  113.     ListLibs();
  114.     break;
  115.   
  116.   /*-- No library names, FLUSH flag, or ALL and FLUSH flags set --*/
  117.   case (LAFF_FLUSH):
  118.   case (LAFF_FLUSH | LAFF_ALL):
  119.     FlushLibs();
  120.     FlushLibs();  /* Seems we need to do this twice.  I wonder why? */
  121.     break;
  122.   
  123.   /*-- Library names, no flags set --*/
  124.   case (LAFF_LIBNAMES):
  125.     for (i=0; LibArgs.LIBNAMES[i] != NULL; i++)
  126.       LoadLib(LibArgs.LIBNAMES[i],REPORT);
  127.     break;
  128.   
  129.   /*-- Library names, LIST flag set --*/
  130.   case (LAFF_LIBNAMES | LAFF_LIST):
  131.     OutputLibInfoHeader();
  132.     for (i=0; LibArgs.LIBNAMES[i] != NULL; i++)
  133.       ListLib(LibArgs.LIBNAMES[i]);
  134.     break;
  135.   
  136.   /*-- Library names, FLUSH flag set --*/
  137.   case (LAFF_LIBNAMES | LAFF_FLUSH):
  138.     for(i=0; LibArgs.LIBNAMES[i] != NULL; i++)
  139.       FlushLib(LibArgs.LIBNAMES[i]);
  140.     break;
  141.   
  142.   /*-- Default --*/
  143.   default:
  144.     OutputUsage();
  145.   }
  146.   
  147.   /* that's all for now, folks! */
  148.   clean_exit(0);
  149.   
  150.   return 0; /* Keep the compiler happy */
  151. }
  152. /* End of the program */
  153.